﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using YoucaiReader.Helper;
using YoucaiReader.Pages;

/**
 * 创建时间：2014/9/20 14:04:36
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace YoucaiReader.UserControls
{
    public static class PopupManager
    {
        public static void PopupBackgroundPanel(this FrameworkElement popupContent, int num)
        {
            Grid parent = popupContent.Parent as Grid;
            if (parent != null)
            {
                Grid grid = parent.Parent as Grid;
                if (grid != null)
                {
                    Grid parent1 = grid.Parent as Grid;
                    if (parent1 != null)
                    {
                        PopupContainerControl popupContainerControl = parent1.Parent as PopupContainerControl;
                        if (popupContainerControl != null)
                        {
                            (popupContainerControl._BasePage as BookReaderPage).BookReader_BackgroundMenu(num);
                        }
                    }
                }
            }
        }

        public static void PopupBottomPanel(this FrameworkElement popupContent, ReaderPageMenuPanel rpmp)
        {
            Grid parent = popupContent.Parent as Grid;
            if (parent != null)
            {
                Grid grid = parent.Parent as Grid;
                if (grid != null)
                {
                    Grid parent1 = grid.Parent as Grid;
                    if (parent1 != null)
                    {
                        PopupContainerControl popupContainerControl = parent1.Parent as PopupContainerControl;
                        if (popupContainerControl != null)
                        {
                            popupContainerControl.CloseTopBottom();
                            switch (rpmp)
                            {
                                case ReaderPageMenuPanel.ProgressPanel:
                                    {
                                        popupContainerControl.ShowPanel(new ProgressControl());
                                        return;
                                    }
                                case ReaderPageMenuPanel.BrightPanel:
                                    {
                                        popupContainerControl.ShowPanel(new BrightControl());
                                        return;
                                    }
                                case ReaderPageMenuPanel.FontPanel:
                                    {
                                        popupContainerControl.ShowPanel(new FontFamilyControl());
                                        return;
                                    }
                                case ReaderPageMenuPanel.BackgroundPanel:
                                    {
                                        popupContainerControl.ShowPanel(new BackgroundControl());
                                        break;
                                    }
                                default:
                                    {
                                        return;
                                    }
                            }
                        }
                    }
                }
            }
        }

        public static void PopupBrightPanel(this FrameworkElement popupContent, double num)
        {
            Grid parent = popupContent.Parent as Grid;
            if (parent != null)
            {
                Grid grid = parent.Parent as Grid;
                if (grid != null)
                {
                    Grid parent1 = grid.Parent as Grid;
                    if (parent1 != null)
                    {
                        PopupContainerControl popupContainerControl = parent1.Parent as PopupContainerControl;
                        if (popupContainerControl != null)
                        {
                            (popupContainerControl._BasePage as BookReaderPage).BookReader_BrightMenu(num);
                        }
                    }
                }
            }
        }

        public static void PopupFontPanel(this FrameworkElement popupContent, int num)
        {
            Grid parent = popupContent.Parent as Grid;
            if (parent != null)
            {
                Grid grid = parent.Parent as Grid;
                if (grid != null)
                {
                    Grid parent1 = grid.Parent as Grid;
                    if (parent1 != null)
                    {
                        PopupContainerControl popupContainerControl = parent1.Parent as PopupContainerControl;
                        if (popupContainerControl != null)
                        {
                            (popupContainerControl._BasePage as BookReaderPage).BookReader_FontMenu(num);
                        }
                    }
                }
            }
        }

        public static void PopupProgressPanel(this FrameworkElement popupContent, float progress)
        {
            Grid parent = popupContent.Parent as Grid;
            if (parent != null)
            {
                Grid grid = parent.Parent as Grid;
                if (grid != null)
                {
                    Grid parent1 = grid.Parent as Grid;
                    if (parent1 != null)
                    {
                        PopupContainerControl popupContainerControl = parent1.Parent as PopupContainerControl;
                        if (popupContainerControl != null)
                        {
                            (popupContainerControl._BasePage as BookReaderPage).BookReader_ProgressMenu(progress);
                        }
                    }
                }
            }
        }

        public static void PopupTopPanel(this FrameworkElement popupContent, ReaderPageMenuPanel rpmp)
        {
            Grid parent = popupContent.Parent as Grid;
            if (parent != null)
            {
                Grid grid = parent.Parent as Grid;
                if (grid != null)
                {
                    Grid parent1 = grid.Parent as Grid;
                    if (parent1 != null)
                    {
                        PopupContainerControl popupContainerControl = parent1.Parent as PopupContainerControl;
                        if (popupContainerControl != null)
                        {
                            popupContainerControl.ClosePopupPanel();
                            popupContainerControl.CloseTopBottom();
                            BookReaderPage bookReaderPage = popupContainerControl._BasePage as BookReaderPage;
                            switch (rpmp)
                            {
                                case ReaderPageMenuPanel.NightPanel:
                                    {
                                        bookReaderPage.BookReader_NightMenu();
                                        return;
                                    }
                                case ReaderPageMenuPanel.ForBeginPanel:
                                    {
                                        bookReaderPage.BookReader_ForBeginMenu();
                                        return;
                                    }
                                case ReaderPageMenuPanel.BookChapterPanel:
                                    {
                                        bookReaderPage.BookReader_BookChapterMenu();
                                        return;
                                    }
                                case ReaderPageMenuPanel.AddMarkerPanel:
                                    {
                                        bookReaderPage.BookReader_AddMarkerMenu();
                                        break;
                                    }
                                default:
                                    {
                                        return;
                                    }
                            }
                        }
                    }
                }
            }
        }
    }
}

